﻿using Common.DataModels;
using Extensions.Attribute.TransactionAttribute;
using Microsoft.AspNetCore.Mvc;
using PLC.Domain.Dto;
using PLC.Domain.Service.Service;

namespace PLC.API.Controllers
{
    [Route("api/device-data")]
    [ApiController]
    public class DeviceDataController : BaseApiController
    {
        private readonly DeviceDataService _deviceDataService;
        private readonly ProductionDataService _productionDataService;

        public DeviceDataController(DeviceDataService deviceDataService,
            ProductionDataService productionDataService)
        {
            _deviceDataService = deviceDataService ?? throw new ArgumentNullException(nameof(deviceDataService));
            _productionDataService = productionDataService?? throw new ArgumentNullException(nameof(productionDataService));
        }
        /// <summary>
        /// 保存生产的气密数据
        /// </summary>
        /// <param name="dtoAirtightDatas"></param>
        /// <returns></returns>
        [HttpPost("process/airtight")]
        [Transaction]
        public async  Task<MessageModel> CreateAirtightDatas(IEnumerable<DtoAirtightData> dtoAirtightDatas)
        {
            await _deviceDataService.CreateAirtightDataAsync(dtoAirtightDatas);
            return Success("保存成功");
        }
        /// <summary>
        /// 保存返修工站的数据
        /// </summary>
        /// <param name="dtoAirtightDatas"></param>
        /// <returns></returns>
        [HttpPost("process/airtight-repair")]
        [Transaction]
        public async Task<MessageModel> CreateRepairAirtightDatas(IEnumerable<DtoAirtightData> dtoAirtightDatas)
        {
            await _deviceDataService.CreateRepairAirtightDataAsync(dtoAirtightDatas);
            return Success("保存成功");
        }
        /// <summary>
        /// 保存气密结果数据
        /// </summary>
        /// <param name="dtoProductionDatas"></param>
        /// <returns></returns>
        [HttpPost("production/airtight")]
        [Transaction]
        public async Task<MessageModel> CreateAirtightResultData(IEnumerable<DtoProductionData> dtoProductionDatas)
        {
            await _productionDataService.CreateAsync(dtoProductionDatas);
            return Success("保存成功");
        }
       
        /// <summary>
        /// 保存ccd发送的数据(数据格式暂定)
        /// </summary>
        /// <param name="ccdData"></param>
        /// <returns></returns>
        [HttpPost("ccd")]
        [Transaction]
        public async Task<MessageModel> CreateCCDDatas(DtoCCDData ccdData)
        {
            await _deviceDataService.CreateCCDDataAsync(ccdData);
            return Success("保存成功");
        }

    }
}
